<template>
  <div>
      <div class="history-header">
      <div class="left">
        <span v-for="(item,index) in headerList" :key="item.id">
          <p :class="curentIndex===index?  'active-p' :''" @click.stop="checkTitle(index)">{{item.title}}</p>
        </span>

      </div>

    </div>
    <div class="recommend">
       <div class="myfollow-useritems" v-for="(item,index) in list" :key="item.uid">
          <div  class="myfollow-userurl">
            <div class="myfollow-userimg" @click="goUserHome(item.uid)">
              <img :src="item.avatar" :alt="item.username" />
            </div>
            <div class="myfollow-userinfo">
              <div class="userinfo-one" @click="goUserHome(item.uid)">
                {{item.username}}
                <!-- <span><img src="public/v.png" alt="" /></span> -->
              </div>
              <div class="userinfo-three">{{item.lable}} </div>
              <div class="userinfo-two">
                <p v-if="item.introduce===''">暂无简介</p>
                <p v-else>{{item.introduce}}</p>
              </div>

            </div>
          </div>
          <div class="myfollow-button" @click.stop='showItemMore(item.uid,index)' >
            <div class="other"><i class="iconfont icon-qita"></i></div>
            <div class="other-more" v-if="follow===index">
                <div class="info-box">
                <div class="close">
                  <i
                    class="iconfont icon-guanbi"
                    title="关闭"
                    @click.stop="follow=-1"
                  ></i>
                </div>
                <div class="more-list" v-if="followState">
                  <div class="more-item" v-if="followState.fllow_mutual" @click="removeFollow(item.uid,index)">互相关注</div>
                  <div class="more-item" v-if="followState.fllow_me" @click="removeFollow(item.uid,index)">取消关注</div>
                  <div class="more-item" v-if="followState.no_fllow" @click="removeFollow(item.uid,index)">关注</div>
                  <div class="more-item" >举报</div>
                </div>
              </div>
            </div>
          </div>
        </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

import http from '@/util/http'

export default {
  props: {

  },
  data () {
    return {
      list: [],
      page: 1,
      curentIndex: 0,
      headerList: [
        {
          id: 1,
          title: '全部'
        },
        {
          id: 2,
          title: '呢称'
        },
        {
          id: 3,
          title: '标签'
        }
      ], // 头部列表
      classify: 'all',
      follow: -1
    }
  },
  computed: {
    ...mapState(['serach', 'user'])
  },
  mounted () {
    console.log(this.serach)
    this.getData()
  },
  methods: {
    // 切换评论内容
    checkTitle (index) {
      this.curentIndex = index
      if (index === 0) {
        this.page = 1
        this.classify = 'all'
        this.getData()
      } else if (index === 1) {
        this.page = 1
        this.classify = 'name'
        this.getData()
      } else if (index === 2) {
        this.page = 1
        this.classify = 'lable'
        this.getData()
      }
    },
    // 获取数据
    getData () {
      http.getuserlist(this.user, this.serach, this.page, this.classify).then(res => {
        this.list = res.data.userList
        console.log(res.data)
      })
    },
    // 跳转到其他用户的个人主页
    goUserHome (uuid) {
      this.$router.push({ path: '/home/userHome', query: { uuid: uuid } })
    },
    // 显示与单个粉丝关注的状态
    showItemMore (id, index) {
      // id列表当前选中的用户id
      // 校验登录
      const checkState = this.$checkU()
      if (!checkState) {
        this.tipsMethod('请先登录', 'icon-jinggao')
        return
      }
      if (localStorage.getItem('token')) {
        http.userfollowState(this.user.uid, id).then(res => {
          console.log(res.data)
          this.followState = res.data.data
          this.follow = index
        })
      }
    },
    // 取消关注的逻辑
    removeFollow (id, index) {
      // 显示弹出框
      this.meshowConsider(true)
      // console.log(id, index)
      // 保存了当前点击取消关注的用户项的下标
      this.cruntIndex = index
      // 保存当前点击取消的用户的id
      this.nid = id

      this.followList[index].itemMore = false
    }
  }
}
</script>

<style lang="scss" scoped >
.recommend {
  display: flex;
  justify-content: space-between;
  height: auto;
  flex-wrap: wrap;
   .myfollow-useritems {
        width: 100%;
        min-height: 70px;
        background: #fff;
        padding: 10px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &:hover {
          background: #eee;
        }

        .myfollow-userurl {
          text-decoration: none;
          color: #333;
          display: flex;
          align-items: center;
          margin-left: 20px;

          .myfollow-userimg {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            overflow: hidden;
            background: #666;
            cursor: pointer;
            img {
              z-index: 1;
              width: 100%;
              &:hover{
                filter: brightness(70%);
              }
            }
          }
          .myfollow-userinfo {
            font-size: 12px;
            line-height: 16px;
            margin-left: 10px;
            .userinfo-one {
              cursor: pointer;
              font-weight: bold;
              display: flex;
              align-items: center;
            }
            .userinfo-two {
              color: #666;
              p {
                width: 100%;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
              }
            }
            .userinfo-three {
              color: #666;
            }
          }
        }
        .myfollow-button {
          // width: 70px;
          // height: 30px;
          // border-radius: 50px;
          // border: 1px solid #000;
          margin-right: 40px;
          display: flex;
          align-items: center;
          position: relative;
          .other {
            margin-left: 15px;
            cursor: pointer;
          }
          .other-more {
            position: absolute;
            top: 20px;
            left: -50%;
            width: 80px;
            min-height: 40px;
            background: #fff;
            box-shadow: 2px 2px 5px rgb(224 224 224),
              -2px -2px 5px rgb(224 224 224);
            border-radius: 5px;
            .info-box {
              padding: 5px 0;
              .close {
                display: flex;
                justify-content: flex-end;
                font-size: 12px;
                padding-right: 5px;
                i{
                  cursor: pointer;
                }
              }
              .more-list {
                width: 100%;
                .more-item {
                  cursor: pointer;
                  text-align: center;
                  font-size: 12px;
                  padding: 5px 0;
                  &:hover {
                    background: #999;
                  }
                }
              }
            }
          }

        }
      }

}
 .history-header {
    width: 100%;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    display: flex;
    background: white;
    padding: 6px 0;
    justify-content: space-between;
    border-radius: 5px;
    margin-bottom: 10px;
    .left {
      color: #666;
      span {
        cursor: pointer;
        padding: 0 10px;
        width: 40px;
        display: inline-block;
        padding: 0 5px;
        text-align: center;
        .active-p {
          font-weight: 700;
          color: #f60;
        }
        p {

          &:hover {
            color: #f60;

          }
        }
      }
      .active {
        color: #f60;
        font-weight: 700;
      }
    }

  }
</style>
